
<link rel="stylesheet" href="__JS__/zTree/css/demo.css" type="text/css">
<link rel="stylesheet" href="__JS__/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="__JS__/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="__JS__/zTree/js/jquery.ztree.excheck.js"></script>
<!--
<script type="text/javascript" src="__JS__/zTree/js/jquery.ztree.exedit.js"></script>
-->
<SCRIPT type="text/javascript">
	<!--
	var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		}
	};

	var zNodes =[
		{volist name="temp_List" id="vo"}
		{ id:{$vo.id}, pId:{$vo.parentid}, name:"{$vo.name}", {if condition="!empty($vo['checked']) and $vo['checked'] eq 'checked'"}checked:true{/if}},
		{/volist}
	];
	
	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		$(".btn_sub").click(function(){
			var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			var nodes = treeObj.getCheckedNodes(true);
			var classpurview = "";
			for(var i=0;i<nodes.length;i++) {
				classpurview += nodes[i].id + ","
			}
			if(classpurview == ''){
				layer.alert('请分配权限', {
					icon: 0,
					title: '提示信息'
				});
				return false;
			}

			var gid = $('#gid').val();
			var url = "{:Url('authorize_post')}";
			$.ajax({
				type: 'post',
				url: url,
				data: {gid:gid,purview:classpurview},
				success: function(data){
					var obj = eval('(' + data + ')');
					if(obj.error != 0){
						layer.alert(obj.msg, {icon: 0});
						return false;
					}else{
						var msgIndex = layer.msg('正在提交信息...', {icon: 6, time:60000});
						layer.close(msgIndex);
						layer.alert(obj.msg, {icon: 0}, function(index){
							var Obj_url = obj.url;
							layer.close(index);
							window.location.href = Obj_url;
						});
					}
				}
			});
		})
	});
	
	function submit_tree(){
		
	}
	//-->
</SCRIPT>
<div class="nav-tabs-custom">
	<ul class="nav nav-tabs">
		<li class=""><a href="{:Url('index')}">列表</a></li>
		<li class="active"><a href="#">权限配置</a></li>
	</ul>
	<div class="box-body">
	
		<form class="js-ajax-form" action="{:Url('authorize_post')}" method="post">
			
			<ul id="treeDemo" class="ztree"></ul>
			
			<div class="box-footer">
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<input type="hidden" name="id" id="gid" value="{$id}" />
						<button type="button" class="btn btn-primary btn_sub">保存</button>
						<a class="btn btn-default" onClick="javascript:history.go(-1);">返回</a>
					</div>
				</div>
			</div>
		</form>
		
	</div>
</div>